import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-06-22
 * Time: 10:35
 */
// 双指针 中心扩散法
class Solution {
    public String longestPalindrome(String s) {
        String res = "";
        String s1  = "";
        String s2  = "";
        for(int i =0;i<s.length();++i){
            s1 = extend(s,i,i);//以一个元素为中心
            res = s1.length()>res.length()?s1:res;
            s2 = extend(s,i,i+1);//以两个元素为中心
            res = s2.length()>res.length()?s2:res;
        }
        return res;
    }
    public String extend(String s,int l,int r){
        //b a b a d
        while(l>=0&&r<s.length()&&s.charAt(l)==s.charAt(r)){
            l--;
            r++;
        }
        return s.substring(l+1,r);

    }
}
public class TestDemo {


    public static void main(String[] args) {
//        Solution solution = new Solution();
//        int[] a = {1,2,3};
//        System.out.println(Arrays.toString(Arrays.copyOfRange(a,0,1)));
//       // System.out.println(solution.longestPalindrome("babad"));
        StringBuilder sb = new StringBuilder();
        int a =0;
        String s = "99";
        sb.append(a);
        sb.append(s);
        System.out.println(sb);
    }


}

class Solution2 {
    //找回文子串并且返回回文子串
    public String PalindromeS(String s,int l,int r){
        //采用两指针相背而行，属于中间扩散型适用于回文
        //两指针不能越界并且判断指针指向的字符是否相等
        while(l>=0&&r<=s.length()-1&&s.charAt(l)==s.charAt(r)){
            l--;
            r++;
        }
        return s.substring(l+1,r);//注意substring是左闭右开
    }
    public String longestPalindrome(String s) {
        String s1 = "";
        String s2 = "";
        String res = "";

        for(int i =0;i<s.length();++i){
            s1 = PalindromeS(s,i,i);//以一个元素为中心找回文子串eg:ab c ba
            res = s1.length()>res.length()?s1:res;//选择长度最大的返回
            s2 = PalindromeS(s,i,i+1);//以两个元素为中心找回文子串eg:a bb a
            res = s2.length()>res.length()?s2:res;//选择长度最大的返回
        }
        return res;
    }
}


